// components/pay-popup.ts
import { request, api } from "../../utils/request"
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    price: {
      type: String
    },
    orderId: {
      type: Number,
      value: 0
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    password:""
  },

  /**
   * 组件的方法列表
   */
  methods: {
    pwdInput(params) {
      console.log(params);
      
      this.setData({
        password: params.detail.value
      })
    },
    async payOrder() {
      let orderId = this.data.orderId
      
      if (orderId <= 0) {
        wx.showToast({ title: '支付失败，参数异常', icon: 'error', duration: 1000, mask: true })
        return
      }
      let res = await request(api.OrderPay, {
        orderId: orderId,
        password: this.data.password
      }, "POST")
      console.log(res);

      if (res.errno !== 0) {
        wx.showToast({ title: res.errmsg, icon: 'error', duration: 1000, mask: true })
      } else {
        wx.showToast({ title: '支付成功', icon: 'success', duration: 1000, mask: true })
        this.triggerEvent('close')
      }
    },
    onClose() {
      this.triggerEvent('close')
    }
  }
})
